﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Demo.Services.Contracts.DTO.Infos;
using System.Data;
using Demo.CommonBase.Logging;
using System.Reflection;
using Demo.CommonBase.Exceptions;

namespace Demo.Services.Integration.DAO.IntegrationComponents.Mappings
{
    public class ReportDAOMapper
    {
        public static List<ProjectReportInfo> GetProjectReportList(DataSet ds)
        {
            List<ProjectReportInfo> result;
            try
            {
                Logger.Info(MethodInfo.GetCurrentMethod().ToString());
                DataTable dt = ds.Tables[0];

                result = (from project in dt.AsEnumerable()
                          select new ProjectReportInfo
                          {
                              Id = project.Field<int>("id"),
                              Name = project.Field<string>("nombre"),
                              ResourcesNumber = project.Field<int>("NRecursos")
                          }).ToList();
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);
            }

            return result;
        }
    }
}
